import { fetchEventSource } from "@microsoft/fetch-event-source";

export async function baseAIFetch(callback) {
  const ctrl = new AbortController();
  fetchEventSource("/fetch-api" + "/answer", {
    method: "POST",
    headers: {
      "Content-Type": "application/json;charset=utf-8",
    },
    mode: "cors",
    body: JSON.stringify({
      query: "你叫什么名字",
      uuid: "17574844970968420",
    }),

    signal: ctrl.signal,
    onerror: (error) => {
      throw error;
    },
    // 自定义重连延迟（毫秒）
    retryDelay: 4000, // 默认 1000ms
    // 最大重试次数
    maxRetries: 2,
    async onmessage(ev) { 
      console.log(ev, "evev");
    },
  });
}
